import {removeToken, setToken} from "@/utils/auth";

const state = {
    user: {
        username: '',
        password: '',
    },
}
const mutations = {
    SET_USER(state, payload) {
        state.user = payload
        let token = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9'
        setToken(token)
    },
    LOGOUT(state) {
        state.user = {}
        removeToken()
    }
}
// const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms))

const actions = {
    async login({commit}, payload) {
        // await sleep(1500);
        commit('SET_USER', payload)
    },
    logout({commit}) {
        commit('LOGOUT')
    }
}
export default {
    namespaced: true,
    state,
    mutations,
    actions
}
